//
// Created by wang on 2021/7/20.
//

#ifndef ENET_MP_H
#define ENET_MP_H

#include "etypes.h"
#include "thr.h"

#define MP_MAX_POOL 200

typedef uint32_t mp_id;

typedef struct mp_blk {
    struct mp_blk *next;
} mp_blk;

typedef struct {
    uint32_t blk_sz;
    uint32_t blk_cnt;
    uint32_t free_cnt;
    uint8_t flags;
    uint8_t *base;
    uint8_t *start;
    uint8_t *end;
    mp_blk *free_blk;
} pool;

typedef struct {
    uint32_t n;
    e_sem_t sem;
    pool *pools;
} pool_info;

void mp_init();
ret_t mp_create(uint32_t sz, uint32_t cnt, uint8_t flags, mp_id *id);

ret_t mp_delete(mp_id );
ret_t mp_alloc(mp_id, uint8_t **);
ret_t mp_alloc_n(mp_id id, uint8_t **block, uint32_t n);

ret_t mp_free(mp_id, const uint8_t *);

#endif //ENET_MP_H
